I made a police light application with a tower light and Arduino

A few days ago I bought a three-color tower light with buzzer for visual and audible alerts. And because I’m a big kid, I thought to build as the first application a game of lights in the style of a police car. The result will be seen at the bottom of this article.

Before entering into the connection and programming area, I give you some details about the product. The tower light has three colors and a buzzer. The tower can be easily controlled by an Arduino board, four N-channel MOSFETs or NPN transistors, and four resistors.

The light tower is branded Adafruit and produced in China. At least this is written on the product that I use in this tutorial. Also, there is a schema somewhere on it with Chinese letters. Thank you Adafruit!

Everywhere I’ve been looking for information about how it works and how I can control it, I’ve given this tutorial. The tutorial is dedicated to the RGB LED strips and less to a light tower. Generally, Adafruit produces good tutorials, so I think that I don’t have to make a great effort to turn ON the lights. But this time I was a bit misguided by the schema with connections found in the tutorial. For the NPN Bipolar Transistors (PN2222), I recommend you carefully look how the three pins of the transistor are located or use the schema from this article. When I connected the light tower just like in the Adafruit’s tutorial (the NPN schema), the result was a tower light that just makes some noise and has two lights on. Obviously, the pins of the transistors were wrongly connected.

Let’s get to the practical side.

Components:

  • 1 X Tower Light – Red Yellow Green Alert Light & Buzzer (I buy it from here, but you can buy it also from Amazon)
  • 4 X NPN Bipolar Transistors (PN2222) (link on Amazon)
  • 4 X 100-220 Ohm resistors (link on Amazon)
  • 1 X Arduino board (I think you already have one, but in case I’m wrong, you can take one from here)
  • some wires (link on Amazon)

The schema:

Tower light and Arduino Schema

Tower light and Arduino Schema

The Arduino code:

//Constants
#define REDPIN 9
#define YELLOWPIN 10
#define GREENPIN 11
#define BUZZ 12

//Variables
int  ledDelay=50;
long previousMillisLights = 0;    
long intervalLights = 500;   
long previousMillisTemperature = 0;    
long intervalTemperature = 1000;  

void setup()
{   
    Serial.begin(9600);
    pinMode(REDPIN, OUTPUT);
    pinMode(YELLOWPIN, OUTPUT);
    pinMode(GREENPIN, OUTPUT);
    pinMode(BUZZ, OUTPUT);

}

void loop()
{
 unsigned long currentMillis = millis();
   
    if ((unsigned long)(currentMillis - previousMillisLights) >= intervalLights) {
    redPoliceLights();
    yellowPoliceLights();
    greenPoliceLights();
  //add here the code if you want the turn on the buzzer
 //analogWrite(BUZZ, HIGH);
   intervalLights = currentMillis;
   }
  }

//turn ON and OFF the red light
void redPoliceLights(){
   analogWrite(REDPIN, HIGH);
   delay(ledDelay);
   analogWrite(REDPIN, LOW);
   delay(ledDelay);
   analogWrite(REDPIN, HIGH);
   delay(ledDelay);
   analogWrite(REDPIN, LOW);
   delay(ledDelay);
   analogWrite(REDPIN, HIGH);
   delay(ledDelay);
   analogWrite(REDPIN, LOW);
   delay(ledDelay);
  }

//turn ON and OFF the yellow light
void yellowPoliceLights(){
   analogWrite(YELLOWPIN, HIGH);
   delay(ledDelay);
   analogWrite(YELLOWPIN, LOW);
   delay(ledDelay);
   analogWrite(YELLOWPIN, HIGH);
   delay(ledDelay);
   analogWrite(YELLOWPIN, LOW);
   delay(ledDelay);
   analogWrite(YELLOWPIN, HIGH);
   delay(ledDelay);
   analogWrite(YELLOWPIN, LOW);
   delay(ledDelay);
  }

//turn ON and OFF the green light
  void greenPoliceLights(){
   analogWrite(GREENPIN, HIGH);
   delay(ledDelay);
   analogWrite(GREENPIN, LOW);
   delay(ledDelay);
   analogWrite(GREENPIN, HIGH);
   delay(ledDelay);
   analogWrite(GREENPIN, LOW);
   delay(ledDelay);
   analogWrite(GREENPIN, HIGH);
   delay(ledDelay);
   analogWrite(GREENPIN, LOW);
   delay(ledDelay);
  }

Tower Light Demo:

The Future Of Robotics – Predictions (AD)

Robotics as a field owes a lot to the introduction of the linear actuator. While this article is not the place for in depth information about electric actuators, they are pieces of equipment which turn rotational motion into linear motion. Linear actuators have changed the way in which robots are used in everyday life, since they have given them a greater scope of movement. Before, robots were fairly clumsy, and so only suited for working in industries which required strength, but no finesse. Now they can work in industries which take precision and delicacy.

The future is an exciting time to be in robotics, since there is so much potential there for them to be and to do. The rapid pace of change in this area, plus the melding with associated areas such as artificial intelligence and machine learning, means that just about anything is possible for the next stage of robotics.

E-commerce
Experts are now saying that by next year, nearly half of all global e-commerce practices will have some robotic presence in them. That robotic presence might be chat-bots which are programmed to answer customer enquiries, or it might be robots used in warehousing and deliveries.

Shared Intelligence
In a few years, almost forty percent of robots which work in commercial environments are supposed to be linked to a shared intelligence network. This shared link will ostensibly give a two hundred percent improvement in their work capacity and operational efficiency.
Read more →

How to use rosserial with two Arduinos and Raspberry Pi

Arduino is a great development board for reading data from various sensors and controlling the robot’s DC motors. Raspberry Pi is good at running ROS on Linux. So, we can benefit from both systems to build smart robots. The easiest way is to connect these boards via USB cable and make them communicate through ROS nodes.

In this tutorial, I’ll show you how to use two Arduino boards as an extension of the Raspberry Pi computer. Before starting writing the ROS nodes, I have to set the Pi to identify each Arduino. This identification becomes necessary when the robot’s architecture is complex.

Only one ROS node can run on an Arduino board. And because I have two Arduino, I will use one to generate a random number and another to control the LED connected to pin 13.

How To use rosserial with Two Arduinos and Raspberry Pi

I will run one ROS nodes that will send and receive data according to this flowchart

The description of the flowchart

  • The user will start all ROS nodes by running a .launch file.
  • The first Arduino board will run a random number script and send data to Raspberry Pi.
  • A ROS node will receive a random number from the first Arduino board. The node will run on Raspberry Pi and will command the LED on the second Arduino board.
  • The second Arduino board will turn ON and OFF the LED (pin 13) depending on the commands received from the ROS node running on the Pi board.

The ROS node for random number generation

#include <ros.h>
#include <ros/time.h>
#include <std_msgs/Int32.h>

int min=1;
int max=5000;
int rand_no;


ros::NodeHandle nh;
std_msgs::Int32 rand_msg;
ros::Publisher pub_random("/random_number", &rand_msg);

char frameid[] = "/randomData";

#this function returns the random number
int random_number(){
rand_no= random(min, max);
return rand_no;
   }

 
void setup() {
   nh.initNode();
   nh.advertise(pub_random);
}


void loop() {
 rand_msg.data=random_number();
 pub_random.publish(&rand_msg);
 nh.spinOnce();
 delay(1000);
 }

Testing the node
Step 1: Open a Linux Terminal and type the command:

roscore

Step 2: Open a second Linux Terminal and type the following command:

rosrun rosserial_python serial_node.py /dev/ttyACM*

Step 3: To see the random numbers generated by the Arduino node, open a third Terminal and type the following command:

rostopic echo /random_number

The ROS node that displays and calculates the LED’s stage

This ROS node in Python will run on Raspberry Pi. Before you start writing the Python code, you must create the workspace and the package that contains the node. All you need to do is in this article.

#!/usr/bin/env python

import rospy

from std_msgs.msg import Int32
from std_msgs.msg import String

var=None

#define the display text
def callback(msg):
    global var
    var=msg.data

 
if __name__=='__main__':
   
 rospy.init_node('random_LED')
 rospy.Subscriber('random_number',Int32, callback)
 pub=rospy.Publisher('LED', String, queue_size=1)
 rate=rospy.Rate(10)

while not rospy.is_shutdown():
     if var<=2500:
        #send message to turn OFF the LED
          varP="OFF"
          rospy.loginfo("The output is OFF and the var is: %s", var)
     else:
        #send message to turn ON the LED
         varP="ON"
         rospy.loginfo("The output is ON and the var is: %s", var)

pub.publish(varP)    
rate.sleep()

The ROS node that controls the LED

#include <ros.h>
#include <std_msgs/String.h>

ros::NodeHandle nh;

void messageCb(const std_msgs::String& msg)
{
  if(msg.data =="ON")
    digitalWrite(13, HIGH-digitalRead(13));   //blink the led
else
   digitalWrite(13, LOW-digitalRead(13));   //turn off the led
}

ros::Subscriber sub("LED", &messageCb);

void setup()
{
  pinMode(13, OUTPUT);
  nh.initNode();
  nh.subscribe(sub);
}

void loop()
{
  nh.spinOnce();
  delay(1000);
}

Write the launch file

<launch>
<node pkg=”rosserial_python” type=”serial_node.py” name=”twoArduino_LED” output=”screen”>
<param name=”port” value=”/dev/ttyACM0″/>
<param name=”baud” value=”57600″/>
</node>
<node pkg=”rosserial_python” type=”serial_node.py” name=”twoArduinos_RandNo” output=”screen”>
<param name=”port” value=”/dev/ttyACM1″/>
<param name=”baud” value=”57600″/>
</node>
<node name=”random_number” pkg=”pi_and_arduino” type=”twoArduinos_Pi.py” output=”screen” />
</launch>

References:

 

Fruit Picking Robots

The robotics designers offer to the farmers the opportunity to significantly reduce the costs of manual labor for harvesting. The robots can replace the seasonal manual work or even permanent employees on farms.

In this article, I made a presentation of the robots designed to replace the manual work in harvesting the fruits. All of the below robots have the ability to detect, recognize, and determine if these are ripe enough to be picked. In addition, they are able to harvest the fruits without damaging them.

Apple-Picking robot with vacuum


Thanks to the start-up Abundant Robotics, apple orchard farmers will be able to use robots instead of seasonal pickers. The AR startup uses the vacuum to pick apples from trees.

The robot uses computer vision algorithms to identify and locate apples in the tree. The technology used is not specifically designed for agriculture. The same technology can be applied in a wide range of industries, but for now they are using it into the agriculture.

Apples require attention at harvesting. The robot is designed to work with precision in harvesting and to store the apples. The collection is made through a flexible hose and the storage is made in the same big boxes as used by the human workers.

The company is already planning the next version of the robot that will have many more robotic arms.

The transition from the prototype to the mass production of the robot is scheduled to start in 2018.
Read more →

Template for a ROS Subscriber Using rosserial on Arduino

A few weeks ago I started writing a series of tutorials that ease the work of beginners in ROS. The first tutorial was about a template for a publisher node, the second tutorial was about a template for a subscriber node in ROS, the third tutorial was a simple ROS subscriber and publisher in Python, and the fourth template is about a publisher using rosserial.

Today, I continue the series of tutorials with a template for a ROS subscriber using rosserial on the Arduino board. In addition, I’ll write a subscriber node based on the below template.

Below you will find the template for a ROS subscriber using rosserial on the Arduino board. To write your own subscriber using rosserial on Arduino, copy the template into Arduino IDE, delete the information that you don’t need and replace the text in capital letters.

ROS and Arduino

#include <ros.h>
#include <std_msgs/THE_TYPE_OF_THE_MESSAGE_YOU_SUBSCRIBER>

//create the ros node nh. The node will be used to publish to Arduino
ros::NodeHandle nh;


void messageCb(const std_msgs::MESSAGE_TYPE& msg)
{
  do_domething with msg.data;
 
}

ros::Subscriber sub("THE_TOPIC_THAT_SUBSCRIBER", &messageCb);

void setup()
{
  nh.initNode();
  nh.subscribe(sub);
}

void loop()
{
  nh.spinOnce();
  delay(10);
}

I used the above template to write a ROS node that will subscribe to a node that generates random numbers.

#include <ros.h>
#include <std_msgs/Int32.h>

ros::NodeHandle nh;

float var;

void messageCb(const std_msgs::Int32 &msg)
{
  var=msg.data;
 
  if(var > 2000)
   digitalWrite(13, HIGH);   // blink the led
      else
   digitalWrite(13, LOW);   // turn off the led
}

ros::Subscriber sub("rand_no", &messageCb);

void setup()
{
  pinMode(13, OUTPUT);
  nh.initNode();
  nh.subscribe(sub);
}

void loop()
{
  nh.spinOnce();
  delay(200);
}

How to run the node
Step 1: Open a new Terminal, type roscore and press the Enter key;
Step 2: Open a new Terminal and run the node to publish the messages;
Step 3: Open another Terminal and start the subscriber node by typing the following command:

rosrun rosserial_python serial_node.py /dev/ttyACM0

Template for a ROS Publisher Using rosserial on Arduino

A few weeks ago I started writing a series of tutorials that ease the work of beginners in ROS. The first tutorial was about a template for a publisher node, the second tutorial was about a template for a subscriber node in ROS, and the third tutorial was a simple ROS subscriber and publisher in Python.

Today, I continue the series of tutorials with a template for a ROS publisher using rosserial on the Arduino board. In addition, I’ll test the template and write a publisher node.

Below you will find the template for a ROS publisher using rosserial on the Arduino board. To write your own publisher using rosserial on Arduino, copy the template into Arduino IDE, delete the information that you don’t need and replace the text in capital letters.

ROS and Arduino

#Template for a ROS Publisher Using rosserial on Arduino

//different specific libraries
#include <ros.h>
#include <ros/time.h>
#include <sensor_msgs/Range.h>
#include <std_msgs/Float32.h>
#include "DHT.h" 

//create the ros node nh. The node will be used to publish to Arduino
ros::NodeHandle nh;

//for example, if you're using an ultrasonic sensor, the sensor message is Range
sensor_msgs::SENSOR_RETURN_TYPE msg;

ros::Publisher pub("/TOPIC_NAME", &msg);
void setup() {
   nh.initNode();
   nh.advertise(pub);
}

void loop() {
  unsigned long currentMillis = millis();

  if (currentMillis-range_timer >= 50) //publish every 50 milliseconds
  {
    range_timer = currentMillis+50;
    pub.publish(&msg);
    }
   
   nh.spinOnce();
}

Read more →

How Robots Are Changing Our World (AD)

Robots were not able to become the force they are today without the invention and subsequent reliance upon linear actuators, equipment which has greatly increased our abilities in terms of what functions can be carried out where. Actuators are pieces of equipment which allow for a much greater degree of control over the speed and precision of certain movements. Having these makes building robots which are more suited to their tasks much easier than before, as we can now create robots which are suited to delicate tasks.

As a result, our ability to build and use robots has changed greatly, with a corresponding effect on how robots are used within our lives as a whole – they already form a huge number of our production lines in car making and other manufacturing, but the increase in their ability to undertake more delicate and precise tasks means that we are now looking to incorporate robots further afield, in industries such as medicine and hospitality, among others. Read more →

How To setup Raspberry Pi to identify two Arduino devices

The applications that run on Raspberry Pi can’t always identify the serial port that belongs to each Arduino board. If we don’t use an identifier for each board, the serial port may change every time we disconnect or connect the Arduino board to Raspberry Pi.

In this tutorial, I’ll show you how to configure Raspberry Pi to automatically identify two Arduino boards. The procedure can be extended to multiple boards, but in this tutorial, I’ve used two identical Arduino boards.

How To setup Raspberry Pi to identify two Arduino devices

How To setup Raspberry Pi to identify two Arduino devices

Below are the steps to identify each board separately, regardless of which USB port of the Pi is used.

Step 1: navigate to /etc/udev/rules.d/99-arduino.rules
Step 2: this command returns the two serial ports connected to the Arduino boards

ls /dev/ttyACM*
ls /dev/ttyACM* for two Arduino boards

ls /dev/ttyACM* for two Arduino boards

Step 3: after finding the KERNEL of the two Arduino boards, run for each board the command:

udevadm info -a -n /dev/ttyACM00 | less

Instead of ttyACM00, use the serial port of the Arduino board
Step 4: for each Arduino’s KERNEL, add a line to the file 99-arduino.rules

Setup Raspberry Pi

Step 5: refresh udev

sudo /etc/init.d/udev reload

Template for a Simple ROS Subscriber and Publisher in Python

A few days ago I started writing a series of tutorials that ease the work of beginners in ROS. The first tutorial was about a template for a publisher node, and the second tutorial was about a template for a subscriber node in ROS.

Today, I continue the series of tutorials with a template for a publisher and a subscriber node in Python. In addition, I’ll test it by writing and running a publisher and subscriber node.

Template for a Simple ROS Subscriber and Publisher in Python

Template for a Simple ROS Subscriber and Publisher in Python (image source)

Copy the template into a ‘. py’ file, delete the information that you don’t need and replace the text in capital letters.

#ROS Node Subscriber & Publisher template

#!/usr/bin/env python

#remove or add the library/libraries for ROS
import rospy, time, math, cv2, sys

#remove or add the message type
from std_msgs.msg import String, Float32, Image, LaserScan, Int32

varS=None

#define function/functions to provide the required functionality
def fnc_callback(msg):
    global varS
    varS==do_something(msg.data)

if __name__=='__main__':
    #Add here the name of the ROS. In ROS, names are unique named.
    rospy.init_node('NODE_NAME')
    #subscribe to a topic using rospy.Subscriber class
    sub=rospy.Subscriber('TOPIC_NAME', THE_TYPE_OF_THE_MESSAGE, fnc_callback)
    #publish messages to a topic using rospy.Publisher class
    pub=rospy.Publisher('TOPIC_NAME', THE_TYPE_OF_THE_MESSAGE, queue_size=1)
    rate=rospy.Rate(10)

    while not rospy.is_shutdown():
        if varS<= var2:
            varP=something()
        else:
            varP=something()

        pub.publish(varP)
        rate.sleep()
   

I used the above template to write a ROS node that will display the random numbers received from another node, then I add some conditional statements, and finally I publish the results.

#!/usr/bin/env python

import rospy

from std_msgs.msg import Int32

varS=None

def fnc_callback(msg):
    global varS
    varS=msg.data
   
if __name__=='__main__':
    rospy.init_node('NODE_SUB_AND_PUB')
   
    sub=rospy.Subscriber('rand_no', Int32, fnc_callback)
    pub=rospy.Publisher('sub_pub', Int32, queue_size=1)
    rate=rospy.Rate(10)

    while not rospy.is_shutdown():
        if varS<= 2500:
            varP=0
        else:
             varP=1
   
        pub.publish(varP)
        rate.sleep()

To run the above node, navigate to the .py file and make it executable. The command is:

chmod u+x my_python_file.py

After the file is executable, you can run the node.

Step 1: open a new Terminal and run the command:

roscore

Step 2: open a new Terminal and run the publisher node with the following command:

rosrun your_package your_ros_node_that_generates_random_number.py

Step 3: open a new Terminal and run the publisher and subscriber node with the following command:

rosrun your_package your_ros_node_for_publisher_and_subscriber.py

Robot Tractors to Work The Land

This article was last modified on 19 July 2017.

Some of the farmer’s responsibilities have already been taken over by the machines. The robot tractors capable of turning around, cultivating or maintaining the land are a common presence in the landscape.

The main objective of the manufacturers is to replace the manual labor for all types of farming activities. But I know, it is too early to talk about such intelligent machines. Until then, in this article, you will find the best robot tractors capable of autonomous operations in agriculture.

  • Greenbot – safety first

    Added on 19 July 2017

    Greenbot

    Greenbot

    Greenbot is an autonomous tractor that uses a diesel engine to generate power.

    Is guided by GPS and has software specially designed to be used by the operator for commands and data analysis.

    The tractor robot comes with a series of systems for detecting obstacles, animals, people, etc. In front, it has mounted a radar and a bumper bar with mobile parts to detect the impact. Additionally, in the bumper are installed other few sensors for detection.

  • Read more →