This is another example using a sensor from the 37 sensor kit, this time we use the one called the KY-033 Hunt sensor module, this looks like this
A more correct name would be a IR Line tracking sensor
The sensor has IR light emitter and detector. The sensor returns the status of the IR light reflected from a surface as ON or OFF. The on board LED shows the status of the sensor. You need to calibrate the sensor first, basically block the sensor and adjust the pot until the led goes on. Then remove the object and the on board LED should go off.
here are the connections I used
Sensor | Wemos Mini |
---|---|
G | GND |
V+ | 3v3 |
S | PIN A0 |
Code
Not overly complex this example, I noticed that using the serial monitor that the value was 559 when no object was present and around 29 when I blocked the sensor so I decided that if the value was under 100 I would switch the built in wemos led off, default being on in this example
[codesyntax lang=”cpp”]
int sensorPin = A0; // select the input pin int sensorValue = 0; // variable to store the value coming from the sensor void setup () { pinMode(BUILTIN_LED, OUTPUT); // Initialize the BUILTIN_LED pin as an output Serial.begin (9600); } void loop () { sensorValue = analogRead (sensorPin); Serial.println (sensorValue, DEC); //debug if(sensorValue <= 100) { digitalWrite (BUILTIN_LED, HIGH); //led off delay(1000); } digitalWrite (BUILTIN_LED, LOW); //led on - default }
[/codesyntax]
Link