Type Here to Get Search Results !

How To Utilize The Serial Monitor For Analog Input In Arduino

We learned that the arduino will convert the 0 to 5 analog signal to a digital number between 0 to 1,023. However sometimes it is not that case, meaning we will get different subset range between, those maximum values, between 0 to 1,023 - not 123 :-), we will get something less than that.


The main reason for this is that every sensor is a little bit different, and will provide a varying range of voltage levels depending on what they are actually sensing. For example, imagine a sensor that generate values between 1v to 3.5v, so in that case, 1v as analog input should be represented by 0 digital value, so, in order to better understand the range of values that a particular sensor is providing. We will use the serial monitoring option to help us visual the values reported by the arduino and based on that we will be able to normalize the data.

Serial communication is used by two digital devices to talk to each other, and in our case the usb connection is the serial communication protocol between our arduino and our computer. We already used it to upload our source code to the arduino board, now, we can use the "serial monitor" included in the arduino programming environment to actually “see” the values that the arduino is reading from such external sensor.

In our case, before using the potentiometer to control another piece of hardware in our project. We will print out the potentiometer’s range, even if the we know the expected result from a potentiometer. Beacuse it is relevant to an analog sensor that we may use in the future.

So let’s move on and start to learn how to set it up and use it. Before we can use the serial communication working with the arduino board. We need to first establish the communications speed between the two devices using the "serial.Begin()" function and we will do it as part of the setup() function using one line of code: serial.Begin(9600);

  1. The number is actually a communication speed parameter measured in baud rate. Where, 9600 baud is a common value that we should use.
  2. For printing information in any location in our code, we have two functions: "serial.Print" and "serial.Println"
  3. They are almost the same except that the second one will print the information and will start a new line.
  4. Now, in our case we would like to print the current value we got from the two variable resistors.

And let’s review the relevant code and the actual result in our project. Please watch this video below, for better understanding and practical view.



Post a Comment

0 Comments