Digital Sensors
- Digital sensors are (more) straight forward (than Analog)
- No matter what the sensor there are only two states: On and Off
- Signal is always either HIGH (On) or LOW (Off)
- Voltage signal for HIGH will be 5V (more or less) on Arduino Uno. Other Arduinos could use different voltages!
- Voltage signal for LOW will be 0V on most systems
Digital Input – Switch (single throw)
Digital Input – Switch (double throw)
NO = normally open C = common NC = normally closed. | Note : The limit switch provided in EG1311 has a different order for NO, C, and NC. The connections in the picture above need to be adapted accordingly. |
Using Digital Input
- Connect digital input to your Arduino using Pins # 0 – 13 (Avoid pins # 0 & 1 though as they are used for Serial later, and pin #11 and 13 as we are already using it)
- Digital Input needs a pinMode function
pinMode (pinNumber, INPUT);
Make sure to use ALL CAPS for INPUT
- To get a digital reading:
int buttonState = digitalRead (pinNumber);
- Digital Input values are only HIGH (On) or LOW (Off)
http://opensourcehardwarejunkies.com/tutorial-03-digitalread-and-serial-port-communication/
C++ | Blocks |
---|---|
void setup() { pinMode (pinNumber, INPUT); } void loop() { int buttonState = digitalRead(2); if(buttonState == HIGH) { // do something } else { // do something else } }]] ></ac:plain-text-body></ac:structured-macro></div></td><td><div class="content-wrapper"><p><ac:image ac:width="350"><ri:attachment ri:filename="image2020-1-21_21-21-50.png" /></ac:image></p></div><p><br /></p><p><br /></p><p>In Tinkercad, we just need to Start Simulation, and click on the switch to turn it on/off.</p></td></tr></tbody></table><p><br /></p><p><br /></p> |