Sunday, January 28, 2018

Lab 10: Using the Serial Port

In this lab we practiced using the serial port and serial debug.  The serial command will allow you to see values from analog sensors.  These values can help you decide how to code the Arduino based on specific values you might be looking for.



We first built the LDR circuit that we previously built with a 10K resistor and connecting to analog pin 0 of the Arduino.  We then coded the Arduino to allow us to use the serial debug.




You can see here that when we cover up the LDR, the resistance changes and this change is registered on the serial debug screen.



We can also code the Arduino such that it will read whatever we want it to read in the serial debug screen.  We changed the code to read "The Sensor reading is" and "ADC counts" by adding it to the code with the Serial.print command.



You can see that the values are still registering on the serial debug screen but now the added words are included based on how the code was changed.



We then practiced using keyboard inputs to trigger the Arduino.  We initialized the serial port again and coded "inChar" into the Arduino which stands for a character or small integer.  After opening the serial monitor and typing numbers and letters, the serial monitor responded with the appropriate response.  The entered characters will get a response based on either dec, hex or binary as specified by the code.



You can see the responses we got in the serial monitor after typing in different characters, numbers and letters.



Next we coded the Arduino to turn a pin on or off based on characters typed into the keyboard.  We used the command: "char inChar = (char)Serial.read();



You can see the prompt in the serial monitor asking for either a 1 or 0.  When the 1 or 0 is pressed you can then see the LED switch on or off based on the code we uploaded.



Lab 10 finished!

No comments:

Post a Comment

Lab 17: Using IR Sensors for flame and line detection for the VEX

In this lab, we used everything we learned in the previous labs to complete this final lab challenge.  The challenge was to navigate a maze ...