Interfacing Arduino with bolt to integrate Moisture sensor

Iv read a number of posts on Interfacing arduino with bolt .
Let me explain my current scenario .
I have a program which utilises a moisture sensor and a water pump , the moisture sensor is suppose to trigger the pump at a certain threshold value , quite simple …or so i thought .

Turns out that the bolt cannot use the moisture sensor directly , i kept getting a reading of 1024 whether the sensor be placed in air or water .
After further looking up i found out that the bolt only supports sensors upto 1V and the moisture sensor uses 5V , which explained why my value was always 1024 . The Arduino uno on the other hand is fully capable of sensing values upto 5v and was giving me the values i needed to see .

I have the following queries regarding this process ,

1) How exactly do i go about integrating the moisture sensor with bolt using arduino to sense values ?
2) In doing so would i have to change the python code which i have written in my Virtual Ubuntu ? if so , then what changes have to be made ?
3) I did some looking up on the process , and forgive me for my lack of intuition if this seems stupid but hear me out…
I realised that we have to use bolts arduino helper library in the arduino IDE to help bolt communicate with the arduino , but my code is on my virtual ubuntu device … im not really sure if im expected to re write my code in the arduino ide ? if not like how is this process suppose to help me get my program to run

This process was quite frustrating to me , and CHEERS :grinning: to whoever takes the time to elaborate and explain to me whats going on and what im suppose to be doing .

The code and connections for this project are as follows
CODE:(before arduino)

import conf
from boltiot import Sms, Bolt
import json, time

minimum_limit = 921
maximum_limit = 1024  


mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)


while True: 
    print ("Reading sensor value")
    response = mybolt.analogRead('A0') 
    data = json.loads(response) 
    print("Sensor value is: " + str(data['value']))
    try: 
        sensor_value = int(data['value']) 
        if sensor_value > maximum_limit or sensor_value < minimum_limit:
            response = mybolt.digitalWrite('0', HIGH)
            print("Making request to Twilio to send a SMS")
            response = sms.send_sms("The Current temperature sensor value is " +str(sensor_value))
            response = sms.send_sms("MOTOR turned on")
            print("Response received from Twilio is: " + str(response))
            print("Status of SMS at Twilio is :" + str(response.status))
        else:
            response = mybolt.digitalWrite('0', 'LOW')
            print("Making request to Twilio to send a SMS")
            response = sms.send_sms("The Current temperature sensor value is " +str(sensor_value))
            response = sms.send_sms("MOTOR is in off condition")
            print("Response received from Twilio is: " + str(response))
            print("Status of SMS at Twilio is :" + str(response.status))

    except Exception as e: 
        print ("Error occured: Below are the details")
        print (e)
    time.sleep(10)

CONNECTION (before arduino)

I would really like to know what changes i have to make in the code and circuit if i have to get it to work .

1 Like

Do you have some resistors? In my opinion, you don’t need to use arduino instead use a voltage divider at the A0 pin of ratio 1/5 to get your 5v values to get in 1v range. Try this method and tell me the updates. you can also drop a message to me if you want to know how to use the divider.

3 Likes

I will check and get back to you , thank you for your reply !

1 Like

Hey , so i read up about voltage dividers and i figured out that i need 2 resistors , 1k and 220 ohm respectively to drop the voltage from 5 to 1 volt , and the voltage between the 2nd resistor R2 is going to be my desired voltage ( 1V ) but im a little confused on how i should lay out my circuit now… could you guide me on how to connect the resistors ? , should i connect it in series with the Vcc of the moisture sensor itself ? which means the moisture sensor would get only 1V of power , while what i actually want is only the resultant voltage which comes out throught A0 to be divided … im a little confused…

hey , i dont think i got the voltage divider method to work , the water and air values dont seem to be differentiable clearly

@vinayak.joshi @rahul.singh1 Developers can i get your help on this ?

Hi @kaushik.s98,

The connection you should do is as follows.

  1. 1 pin of the 1k resistor to the output of the Soil moisture sensor module. (Colored yellow in the schematic).
  2. 2nd pin of the 1k resistor to A0 pin of the Bolt WiFi module.
  3. 1 pin of the 220ohm resistor to the A0 pin of the Bolt WiFi module.
  4. 2nd pin of the 220 ohm resistor to the GND pin of the Bolt WiFi module.
1 Like

Thank You @vinayak.joshi Sir, it Works perfectly now.

1 Like

I have done exactly as you instructed , a 1k resistor between moisture analog output and A0 pin on bolt and a 220 ohm resistor betwwen A0 of bolt and GND … yet i get indistinguisable values between water and air , i even purchased a new capacitive soil moisture v2.0 and i have the same inaccuracy :frowning:

Is there something else i can try , if not then , how do i modify my code such that i can interface my arduino to sense these values for the bolt ?

Thank you for your previous response . I really want to finish this project , i would appreciate your support .

Current connections (only moisture )
@vinayak.joshi

Hi @kaushik.s98,

Can you share a photo of the full system?
What readings are you getting from the system?
Also, please try putting the sensor in slightly wet soil (2 cups of soil, 2 spoons of water) and check what king of readings you get over a period of 2 hours.

Heres an image of the full system , i temporarily removed the motor for debugging .

These are the values i get

AIR :

SOIL ( quite moist - 5 spoons of water ) :

WATER :

Each value was recorded after 2 min intervals , and let to run for an hour .

As you can observe the values are very inconsistent and there is no difference between water and open air , where as the same sensor on the arduino gives an immediate response when put in water with a very evident change in analog values .

I would really like it if you could tell me how to modify my code such that it can use the arduino to sense the values using either software or hardware serial to communicate with bolt .

Thank you for helping me so far , i appreciate your efforts @vinayak.joshi

Hello @kaushik.s98,
Why don’t you use Arduino in your project to make it simple?

if you read my post , that is my whole question , if you can guide me through the process that would be great

Then, its so simple buddy, just set your threshold value , and when the sensor trigger the sensor value make any of the digital pin as “High”. Now connect that digital pin with the bolt’s digital pin.

Now write python code to read the digitapin value ,

a=mybolt.digitalRead('0')
data = json.loads(a)
b=int(data['success'])
while(b == 1):
response =mybolt.digitalRead('0')
data1 = json.loads(response)
c=int(data1['value'])
if(c==0):
//put your pump off
if(c==1):
//put your pump on
sms.send_sms("Write your message here.") # Call function to
send SMS

hope it will help. :slight_smile:
if not fell free to ask, I will tell you every steps with the exact code , just give it a try ,I hope it will work. :slight_smile:

1 Like

Hey thanks man , im familiar with the logic and code , my problem is getting the Arduino to talk to the bolt and how im suppose to set up the Arduino so that it sends the values to the bolt cloud .

I wanna know how to use the boltarduinohelper library to read the analog value and pass it on the the bolt cloud

It’s quite inconvenient to communicate with you over the forum , cause the replies take so long , would it be appropriate for me to personally contact you ? Whatsapp or some social media

Hello @kaushik.s98 ,
sorry for being late , as you said , you want to communicate the bolt with arduino and get the sensor value to bolt, then for that purpose you need to be clear you actually cannot send the sensor values connected with the Arduino directly to the bolt, the bolt can only read the output displayed in the serial monitor. As I think so, and as of my experience while working with the bolt.
Since you only can read the serial monitor of the Arduino through bolt sometimes it gives a lil bit of error.
So as per my opinion it is better to do the logical part in the Arduino and the feedback part to the bolt.

You can also drop me a mail , ayanghosh974@gmail.com :slight_smile:

And sorry, I have’t used the boltarduinohelper library yet, so I don’t have much knowledge about that.