Here we create a remote light sensor using a stand-alone HM-10 and a Light Dependent Resistor (LDR). The LDR is connected to peripheral HM-10 pin PIOB. Using MODE1 means we can read the value of PIOB from the Central HM-10 over the wireless connection.
HM-10 Set up
The two modules have been set to auto connect using AT+IMME1 and the Peripheral module is in MODE1.
Circuit
The Master or Central HM-10 is connected to an Arduino. The Peripheral or Slave HM-10 has an LDR connected to PIOB. I have the remote HM-10 powered from a bread board power adapter but you could also use a battery. The remote HM-10 has +5v on vcc and +3.3v going to the LDR.
Sketch
The sketch is very simple, it sends “AT+ADCB?” and gets the reply. “AT+ADCB?” requests the voltage on pin PIOB of the remote HM-10.
// Sketch: HM-10_Example_04A_RemoteLightSensor // // Master HM-10 // Pins // BT VCC to Arduino 5V out. // BT GND to GND // Arduino D8 (ASS RX) - BT TX no need voltage divider // Arduino D9 (ASS TX) - BT RX through a voltage divider // // Remote HM-10 // HM-10 vcc to +5V // HM-10 GND to GND // HM-10 PIOB to LDR/CDS #include AltSoftSerial BTSerial; char c=' '; char reply[30]; int pos = 0; void setup() { Serial.begin(9600); Serial.print("Sketch: "); Serial.println(__FILE__); Serial.print("Uploaded: "); Serial.println(__DATE__); Serial.println(" "); Serial.println("The HM-10s should be set for auto connect"); Serial.println("The remote HM-10 should be set for MODE1"); BTSerial.begin(9600); Serial.println("BTserial started at 9600"); Serial.println(" "); } void loop() { BTSerial.print("AT+ADCB?"); delay(500); pos = 0; while ( BTSerial.available() ) { c = BTSerial.read(); reply[pos] = c; pos++; } reply[pos] = '\0'; Serial.print("Reply = "); Serial.println(reply); delay (3000); }
I am simply displaying the results in the serial monitor but you could set up something like a flashing LED on the Arduino to warn you when a light turns on (or off).
Hi Martyn,
I’m doing something similar to your LDR example. I have a remote HM10 (which is connected to a sensor) and a central HM10. My problem is that I need to start the connection between the modules once the sensor detects, not before. How can I do this? I canĀ“t send an “AT+CON” from the remote HM10 to do it. Thanks
I don’t think you can through software but you could try contacting Jinan Huamao on support@jnhuamao.cn. I have found them to be fairly helpful.
Can the sensor to used to switch the power to the HM-10? Then have the HM-10s set up for auto connect. If not I would probably use another microprocessor.