Arduino things I find useful

Arduino code to read a number from a PC or connected device in arduino through serial connection

I have problems in getting to grips with serial communication in the Arduino. Sending serial data to a connected device, usually a PC is straightforward, the device has a buffered reader to read the arduino output as usuable strings and integers. But getting the Arduino to read a number sent from a device is tricky. Say the number you want to send is 2333, the numbers are sent one by one as ascii which then has to be read into a char array (arduino string). Then the string can be transformed into an integer with the atoi function. To view the code click here

Circuit diagram for fading an LED with PWM using a resistor

Below picture shows a photo of the wiring to fade an LED using a pwm pin on the Arduino. It is a good circuit to test communication and the quality of sensor inputs. Remember short leg of an LED is ground and long leg is positive.

The code to run a simple loop can be picked up here.

fadingLED

Below is an illustration of the postioning of wires and resistor in the simplest sensor circuit