Looking for appropriate sensors for medium diploma graduation projects

Go To Last Post
24 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 

After the thread of my problem of starting the ADC module, and then after learning how to activate it, I was able to proceed my testing to the joystick module.

 

So, after learning how to adjust the ADC, the application of the joystick was to read the xy-axis and also to read the push button, there was a problem of reading the push button, but I fixed that with the PCINT interrupt, and I was quite happy to work with interrupts.

 

But Mr Kartman pointed to me that I could use "soft" timer to run the tasks simultaneously without using hardware interrupts and of course that means saving the hardware interrupts for more important tasks. The title of using this method I would like it to be part of this thread, if not then let's leave it for now until I get to the part in the projects where I need to apply this strategy.

 

So, as the title of this thread which is about sensors. Let me list the projects I recommended for the students, and then investigate the required sensors for the projects and which sensors are the best for the applications I want.

 

1. 3-way traffic system, with red light and speed radars.

In this project; the traffic lights are easy would be red, green and yellow LEDs.

But the sensors are what I want to know more about; like, how to operate them in the proper and suitable way for the specific project.

 

I'm thinking of this module as it would be suitable for all the sensing elements for most of the projects.

Related image

 

It emits IR and receives the reflected signal, it has a range of like 0.1 to 11 cm roughly. It's cheep I can order a lot of it, as it can get the job done.

1. For speed radars, I can put two module for a specific range to cover; like, 5 cm, and if a car triggers the first IR module and triggers the second one, then I measure the time between the 2 triggers and calculate the speed; just for demonstration << would this method work? I can wave my hand and it catches the moves so I based on this test that it should work with small car toys.

2. For red light violation sensing: It should work just the same for any moving car in from of the un-allowed area for each way.

=======================================================================================================================

 

2. This project is an idea of my colleagues, which is a warning system on the highways in the city, if there's problems or traffic jam in a specific area on the highway, that there are sensors on the two ends of this area which counts the number of cars, if the number is too high then there's a problem or jam, so based on this result, the system warns the people coming before this area that there's a problem and they have the chance to change their way and take any near exit. And that should help in not getting the situation worse.

 

So for the hardware I think that IR module should work too.

 

 

=======================================================================================================================

3. Greenhouse system, in this project, of course there are other types of sensors; like, vibration, humidity and temp., wind .. etc.

 

I would like to know about any suggestions or recommendations for this project.

 

=======================================================================================================================

4. Power saving system for buildings;

In the college we have part of this method which is a timer to switch off the air conditioning packages like on 4:30 PM, and that's it, no more power saving system, to switch off any lights which could be ON all the night. I'm not thinking of other things to switch off besides the lights, because there are refrigerators, computers and any other appliances that it's important to stay ON.

 

I suggested that we may place the same IR modules on the doors of the building and count the people coming in/out from the start of the day, and at 4:30 PM if the counters reads 0 which means that there are no people, then it switches all the lights OFF. Didn't think of another functionality to add other than lights. Maybe monitors, but monitors go to standby mode which saves power.

 

=======================================================================================================================

 

5. I still need one more project idea, of course there are many on the web but as you noticed I'm looking for systems that are not very difficult for the students to do. Some students told me of using piezoelectric modules to get electricity from walking people but I think they are expensive, am I right?

 

 

 

What I'm asking now from you is that what you think of the implementation of the IR modules? Are there any suggestions for recommendations for different ways to implement the hardware or software parts or other project ideas.

 

Thanks :)

Last Edited: Mon. Sep 17, 2018 - 09:09 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Lots of great sensors to find and choose from, for starters, check out sparkfun.com  Adafruit.com Jameco.com and allelectronics.com  Also search Arduino sensors, that should find a ton of examples and ideas.

 

For the green house project, take a look at the weather station Arduino board at sparkfun, it has light, temp, humidity as well as wind speed and direction, and rain fall sensors.  All with schematics and data sheet links to the chips used.

 

Good luck with your projects.

 

Jim

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please note that the Project forum (the one with the thread !!DO NOT POST HERE!!) is only for finished project, I have moved the thread to the tiny and mega forum.

 

edit spelling

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Last Edited: Tue. Sep 18, 2018 - 12:45 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:

Lots of great sensors to find and choose from, for starters, check out sparkfun.com  Adafruit.com Jameco.com and allelectronics.com  Also search Arduino sensors, that should find a ton of examples and ideas.

 

For the green house project, take a look at the weather station Arduino board at sparkfun, it has light, temp, humidity as well as wind speed and direction, and rain fall sensors.  All with schematics and data sheet links to the chips used.

 

Good luck with your projects.

 

Jim

 

Thank you for the hints and ideas.

 

OK, now I'm working on preparing the projects.

 

I'm now having an issue with the IR sensor, the one I've posted above, with PCINT, it hangs the system! Reading PCINT with a push button works fine. I know I have to implement other strategies other than hardware interrupts, but for now I just have to solve the PCINT problem and move on to the next strategy and then compare how both methods works.

 

js wrote:

Please note that the Project forum (the one with the thread !!DO NOT POST HERE!!) is only for finished project, I have moved the thread to the tiny and mega forum.

 

edit spelling

Thanks for the help :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

What signal is the sensor outputting? Have you measured it? Ages ago we recommended getting a salaea clone logic analyser. Now is the time you need one.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm at work and got a digital oscilloscope. I got these pictures:

 

1. VCC and the Idle HIGH state of the sensor are the same:

 

 

3. This is in the Active LOW state:

 

But it's not entirely 0V, but should work as a LOW voltage.

 

3. Flickering issue, I think this is the unstable state of this sensor it's not a long range sensor so I have to coop with its specs and design the projects according to that it's a small range.

 

Here I changed the T/DIV:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Here’s a little challenge for you since you have an oscilloscope - in your pcint isr, set a port bit on entry, then clear the port bit on exit. Display the port bit on channel 2 of the scope. What do you observe? How long does it take for the isr code to Execute? How long does it take between the pcint changing state until the isr code executes?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

ki0bk wrote:
take a look at the weather station Arduino board at sparkfun, it has light, temp, humidity as well as wind speed and direction, and rain fall sensors.

Another multi-faceted weather sensor:

Since the imposition of the trade tariffs in the US, the weather stone might be hard to find.  (That situation may be different in your country.)  There is a substitute model:

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Tue. Sep 18, 2018 - 03:00 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, I left the work, got home. I also have a logic analyzer, just sat up the tool and downloaded the software, easy tested the IR module and got an amazing result!

 

Yes there's a lot of debouncing. But I thought that won't affect interrupts, because every bounce it would issue an ISR but the CPU still working on executing other instructions << I think so, but it's probably affecting the system.

 

These are my results:

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
Here’s a little challenge for you since you have an oscilloscope - in your pcint isr, set a port bit on entry, then clear the port bit on exit. Display the port bit on channel 2 of the scope. What do you observe? How long does it take for the isr code to Execute? How long does it take between the pcint changing state until the isr code executes?

 

Now I connected the logic analyzer pin to output LED and started to activate the IR module without ISR:

 

 

 

With ISR:

 

 

This is the code I did:

In main program:

#include "interrupts.h"

int  main(){
  cli();
  INTERRUPTS_init();

  sei();
  while(1){
  PORTB |= (1<<PB4);
  }
}

In library:

#include <avr/io.h>
#include <avr/interrupt.h>
#include <inttypes.h>
#include <stdio.h>
#include "interrupts.h"

void INTERRUPTS_init(void)
{	
	DDRC=0xE0;								// put PC4 as input 
	DDRB=0x30;								// put PB4 as output
	PCICR|=(1<<PCIE1);PCMSK1=(1<<PCINT12);  // enable interrupts for PCINT
}


ISR(PCINT1_vect)
{
	cli();
	if (!(PINC&(1<<PINC4)))
	{
		PORTB &= ~(1<<PB4);
	}
	reti();
}

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
ISR(PCINT1_vect)
{
	cli();
	if (!(PINC&(1<<PINC4)))
	{
		PORTB &= ~(1<<PB4);
	}
	reti();
}

So, what inspired you to put that cli(); in your ISR code, when the datasheet clearly says

When an interrupt occurs, the Global Interrupt Enable I-bit is cleared and all interrupts are disabled.
 

?

 

What inspired you to put that reti() in your ISR code, and force an abrupt exit from the ISR before the necessary cleanup/unwinding/epilogue has been done?

 

I thought I had given you a link to your toolchain's documentation on interrupt handling.  Must have been too long an article.  What does it say about reti() ?

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

So, what inspired you to put that cli(); in your ISR code, when the datasheet clearly says

When an interrupt occurs, the Global Interrupt Enable I-bit is cleared and all interrupts are disabled.

?

Most of the information I got from this link:

https://www.nongnu.org/avr-libc/user-manual/group__avr__interrupts.html#ga3b991e8168db8fc866e31f9a6d10533b

 

for cli(); I thought that, as reading through the page, I said "OK this should be at the start of the ISR to prevent other interrupts to cut the execution of the current interrupt" and it's also from my basic simple theoretical background about interrupts, as I don't have much practical experience with interrupts.

 

 

 

What inspired you to put that reti() in your ISR code, and force an abrupt exit from the ISR before the necessary cleanup/unwinding/epilogue has been done?

On the same link in the part of this command, it says:

This should be the last command executed before leaving an ISR

I thought "well as if I'm doing cli(); at the beginning, then I should put this at the end".

 

I thought I had given you a link to your toolchain's documentation on interrupt handling.  Must have been too long an article.  What does it say about reti() ?

Which one? Is it the same link as I posted here or another one? Is it the one talking about ARM interrupt system?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1
ISR(PCINT1_vect)
{
  8a:	1f 92       	push	r1
  8c:	0f 92       	push	r0
  8e:	0f b6       	in	r0, 0x3f	; 63
  90:	0f 92       	push	r0
  92:	11 24       	eor	r1, r1
	cli();
  94:	f8 94       	cli
	if (!(PINC&(1<<PINC4)))
  96:	34 9b       	sbis	0x06, 4	; 6
	{
		PORTB &= ~(1<<PB4);
  98:	2c 98       	cbi	0x05, 4	; 5
	}
	reti();
  9a:	18 95       	reti
}
  9c:	0f 90       	pop	r0
  9e:	0f be       	out	0x3f, r0	; 63
  a0:	0f 90       	pop	r0
  a2:	1f 90       	pop	r1
  a4:	18 95       	reti

Given the above, what is happening to your stack?  Where do you think the forced RETI is sending your program counter?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

wolfrose wrote:
for cli(); I thought that, as reading through the page, I said "OK this should be at the start of the ISR to prevent other interrupts to cut the execution of the current interrupt"

???  What does the datasheet say? 

Certainly there is a place for cli() in many apps.  What does the description say -- for atomic access to multi-byte variables is mentioned.  It says nothing about ISRs.  (...but it DOES in the reti() description -- are you naked?  I think not.)

wolfrose wrote:
On the same link in the part of this command, it says: This should be the last command executed before leaving an ISR

Sigh.

#define reti (   )  

Returns from an interrupt routine, enabling global interrupts. This should be the last command executed before leaving an ISR defined with the ISR_NAKED attribute.

This macro actually compiles into a single line of assembly, so there is no function call overhead.

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Note that as you are investigating a puzzling situation, you also could have examined the generated code.  You also could have used a simulation session to uncover the stack problem.

 

I've lost track yet again.  This thread, I thought, was about selecting sensors for academic projects.  Now it has something to do with clearing an output bit?

 

PLEASE read the datasheet sections on interrupts.  PLEASE read and understand this Tutorials forum article: https://www.avrfreaks.net/forum/...

PLEASE take a pass though this tutorial: https://www.avrfreaks.net/forum/...

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Tue. Sep 18, 2018 - 08:05 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

It helps to look at the assembler output to see what the compiler is doing.

An empty interrupt routine defined like this:

 

ISR(PCINT1_vect) {
  // do nothing
}

 

generates this code (assuming avr-gcc):

 

00000080 <__vector_4>:

ISR(PCINT1_vect) {
  80:   1f 92           push    r1
  82:   0f 92           push    r0
  84:   0f b6           in  r0, 0x3f    ; 63
  86:   0f 92           push    r0
  88:   11 24           eor r1, r1
  // do nothing
}
  8a:   0f 90           pop r0
  8c:   0f be           out 0x3f, r0    ; 63
  8e:   0f 90           pop r0
  90:   1f 90           pop r1
  92:   18 95           reti

 

The services provided are:

  • save r1 (zero reg) and r0 (temp reg)
  • save status flags (SREG)
  • clear r1 to zero
  • run the interrupt code (which is empty)
  • put back SREG
  • put back r0 and r1
  • return and reenable interrupts

 

If your ISR actually does something, many more registers may get pushed

onto the stack and then popped back off at the end of your function.

 

So don't do a reti yourself or the stack will be completely messed up!!

 

--Mike

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

Given the above, what is happening to your stack?  Where do you think the forced RETI is sending your program counter?

I'm sorry I have to say I don't have much experience with AVR assembly, I have worked little with PIC assembly in my start in learning microcontrollers then I switched to C, then moved to Arduino and back to AVR. But didn't worked or compiled any AVR assembly code.

 

But here's my try:

  8a:   0f 90           pop r0
  8c:   0f be           out 0x3f, r0    ; 63

Is this the problem? that actually the saved data of the SREG is popped out before retrieving its saved data back to SREG? is this the problem? 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

???  What does the datasheet say? 

Certainly there is a place for cli() in many apps.  What does the description say -- for atomic access to multi-byte variables is mentioned.  It says nothing about ISRs.  (...but it DOES in the reti() description -- are you naked?  I think

OK only for ATOMIC.

 

So I have to remove cli() and reti() and only use sei() only at the beginning of the program, but also I can just enable the I-bit in SREG to enable interrupts instead of sei() command, right?

 

theusch wrote:

Note that as you are investigating a puzzling situation, you also could have examined the generated code.  You also could have used a simulation session to uncover the stack problem.

 

 

I've lost track yet again.  This thread, I thought, was about selecting sensors for academic projects.  Now it has something to do with clearing an output bit?

It is but for now I want to solve the problem of using the IR module as it's one of the most important sensors in more than one project, also I decided that I'm not looking for other types of IR sensors, I found the module I posted at the beginning is cheap on Aliexpress and it works ok with a long range of 10-11cm, it should be enough for the projects.

 

Of course I opened this thread for that I might investigate other sensors in the coming days, but for now this sensor is the most important one, and also learning how to run multiple tasks is very important to me right now, so I'm focusing on these two problems for now.

 

PLEASE read the datasheet sections on interrupts.  PLEASE read and understand this Tutorials forum article: https://www.avrfreaks.net/forum/...

PLEASE take a pass though this tutorial: https://www.avrfreaks.net/forum/...

OK, but now I have to go sleep it's 11:37 PM in my country :) I have to get up at 6:30 AM.

 

Thank you so much for supporting me.

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

wolfrose wrote:
is this the problem?

The problem is the use of the reti().  Just don't do it.  done.  If you cannot see where reti/pop/pop/pop/reti is going wrong then I probably cannot help you further.  I posted the resulting code; Mike gave a detailed explanation.

wolfrose wrote:
but also I can just enable the I-bit in SREG to enable interrupts instead of sei() command, right?

What do you think the SEI command does?  When you study the AVR Instruction Set document, which op code sets the I bit in SREG?

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

The problem is the use of the reti().  Just don't do it.  done.

Done

 

If you cannot see where reti/pop/pop/pop/reti is going wrong then I probably cannot help you further.  I posted the resulting code; Mike gave a detailed explanation.

Yes I couldn't figure out the problem from the ASM code. But thanks for help.

 

What do you think the SEI command does?

Enables interrupts by setting the global interrupt mask. 

 

It sets the interrupts.

 

I did this in my program code:

  cli();
  INTERRUPTS_init();
  sei();

in the initialize section for prevent any unwanted interrupts during initializations. Then set interrupts back.

 

 

 

When you study the AVR Instruction Set document, which op code sets the I bit in SREG?

Global Interrupt Enable, sei

 

Last Edited: Tue. Sep 18, 2018 - 08:55 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

I've lost track yet again.  This thread, I thought, was about selecting sensors for academic projects.  Now it has something to do with clearing an output bit?

 

But now I'm getting into more serious issue with the sensor and output triggering, it turns out it's really important for my projects.

 

Is it possible to change the title to "investigation on the IR module with ISR" or testing IR sensor with ISR?

 

I can look for sensors as ki0bk suggested to me, it's easy but the operation and how to deal with interrupts is more important to me now. So what you think I should do now?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm doing some experiments with the logic analyzer, here's my testings for an input IR and output LED in the ISR without any delays just for trigger.