SAP HANA IoT Internet of Things: Raspberry, Arduino Uno, XSJS & SAPUI5

In this article we are going to perform:

Step 1 – Connect our Arduino to a Computer and checking if the analog input is working perfectly

For this experiment we have photo sensors that will detect the light intensity and give the data to a computer by serial port communication.

First, install the Arduino Kit from here, to your computer. In our scenario, we will be using Windows.

It looks like this after the installation:

SAP HANA IoT Internet of Things: Raspberry, Arduino Uno, XSJS & SAPUI5

Check also the serial port which is connected to Arduino and set the right port in your installed software.

Now, for this demo we are going to follow the circuit diagram below:

SAP HANA IoT Internet of Things: Raspberry, Arduino Uno, XSJS & SAPUI5

Our circuit looks like this:

SAP HANA IoT Internet of Things: Raspberry, Arduino Uno, XSJS & SAPUI5

Let’s have a look at the code which takes analog input from serial output:

  1. /*
  2. Analog input, analog output, serial output
  3. Reads an analog input pin, maps the result to a range from 0 to 255
  4. and uses the result to set the pulsewidth modulation (PWM) of an output pin.
  5. Also prints the results to the serial monitor.
  6. The circuit:
  7. * potentiometer connected to analog pin 0.
  8. Center pin of the potentiometer goes to the analog pin.
  9. side pins of the potentiometer go to +5V and ground
  10. * LED connected from digital pin 9 to ground
  11. created 29 Dec. 2008
  12. modified 9 Apr 2012
  13. by Tom Igoe
  14. This example code is in the public domain.
  15. */
  16. // These constants won’t change. They’re used to give names
  17. // to the pins used:
  18. const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
  19. const int analogOutPin = 9; // Analog output pin that the LED is attached to
  20. int sensorValue = 0; // value read from the pot
  21. int outputValue = 0; // value output to the PWM (analog out)
  22. void setup() {
  23. // initialize serial communications at 9600 bps:
  24. Serial.begin(9600);
  25. }
  26. void loop() {
  27. // read the analog in value:
  28. sensorValue = analogRead(analogInPin);
  29. // map it to the range of the analog out:
  30. outputValue = map(sensorValue, 0, 1023, 0, 255);
  31. // change the analog out value:
  32. analogWrite(analogOutPin, outputValue);
  33. // print the results to the serial monitor:
  34. Serial.println(sensorValue);
  35. // wait 5 milliseconds before the next loop
  36. // for the analog-to-digital converter to settle
  37. // after the last reading:
  38. delay(500);
  39. }

Here we are trying to read the analog signal from the photo sensor, via Arduino, and then Arduino will send it via serial port to the computer and use it to show the data sensor reading.

After writing the program you should upload the program to the Arduino Uno.

SAP HANA IoT Internet of Things: Raspberry, Arduino Uno, XSJS & SAPUI5

And now to see the magic happening, open the serial monitor in top right side of the program.

We have demonstrated the result of the step 1 in a short video:

In the next blog post we are going to configure Raspberry Pi to ready serial data.

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. Vishesh Agrawal

    Hi Ajay ,

    Thanks for this awesome blog. I been playing around with Arduino board and was think is it possible to directly use Arduino board in HCP instead of Pi..? Do have any sample of how can we set it up?

    (0) 

Leave a Reply